package com.stox.ui.javafx.core.application;

import java.util.Locale;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Component;

@Component
public class ApplicationButton extends Button implements BeanFactoryAware{
	
	private BeanFactory beanFactory;
	
	public ApplicationButton() {
		setId("apps-button");
		setOnAction(new EventHandler<ActionEvent>(){
			@Override
			public void handle(ActionEvent arg0) {
				ApplicationPopOver applicationPopOver = beanFactory.getBean(ApplicationPopOver.class);
				applicationPopOver.show(ApplicationButton.this);
			}
		});
	}
	
	@Override
	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		this.beanFactory = beanFactory;
	}
	
	@Autowired
	public void setMessageSource(MessageSource messageSource) {
		setText(messageSource.getMessage("Applications", null, Locale.getDefault()));
	}
	
}
